<script type="text/javascript">
    RED.nodes.registerType('set-view',{
        category: 'FUXA',
        color: '#a6bbcf',
        defaults: {
            name: {value:""},
            viewName: {value:"", required:true}
        },
        inputs:1,
        outputs:1,
        icon: "white-globe.png",
        label: function() {
            return this.name||this.viewName||"set view";
        },
        oneditprepare: function() {
            $.getJSON('/nodered/fuxa/views', function(data) {
                var datalist = $('#fuxa-views');
                datalist.empty();
                data.forEach(function(view) {
                    datalist.append('<option value="' + view.name + '">' + view.name + '</option>');
                });
            });
        }
    });
</script>

<script type="text/x-red" data-template-name="set-view">
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
    <div class="form-row">
        <label for="node-input-viewName"><i class="fa fa-desktop"></i> View Name</label>
        <input type="text" id="node-input-viewName" list="fuxa-views" placeholder="View Name">
        <datalist id="fuxa-views"></datalist>
    </div>
</script>

<script type="text/x-red" data-help-name="set-view">
    <p>Set the current view in FUXA.</p>
    <p>The result is set to <code>msg.payload</code>.</p>
    <p>Use <code>msg.viewName</code> to override the configured view name.</p>
    <p><strong>Available views:</strong> Dropdown populated from FUXA project views.</p>
</script>